var Json={
    projectId:localStorage.getItem("projectId"),
    pageIndex:1,
    pageSize:5

}
ajax.post(ajax.myUrl+"project/projectDetails",Json,function(result){   
    var data=result.dataset.memberList.members
    var container = document.getElementsByClassName("container")[0];
    console.log(data)
    for(var i=0;i<data.length;i++){
        var newDiv = document.createElement("div");
        newDiv.setAttribute("class","container-content")
        newDiv.innerHTML=`
        <span  class="name">${data[i].userName}</span>
            <span class="phone">${data[i].userPhone}</span>
            <span class="status">${data[i].status}</span>   
         `;
         container.appendChild(newDiv);
    }
    //子项目列表
    var data2=result.dataset.childProjectList.projectList
    console.log(data2)
    var content2 = document.getElementsByClassName("content2")[0];
    // console.log(content2)
    var tbody=content2.querySelector("tbody")
    for(var i=0;i<data2.length;i++){
        var newtr = document.createElement("tr");
        newtr.innerHTML=`
         <td>${data2[i].childProjectId}</td>
             <td>${data2[i].childProjectName}</td>
             <td>${data2[i].childProjectLeader}</td>
             <td>${data2[i].workingHours}</td>
             <td>${data2[i].startDate}</td>
             <td>${data2[i].endDate}</td>
             <td>${data2[i].progress}</td>
             <td class="color">详情</td>
         
         `;
          tbody.appendChild(newtr);
     }
     //添加子项目
     // 给第一个模态框（添加项目）添加事件 点击取消或者确定 模态框消失
     var selects=document.querySelector("#addChildProject").querySelectorAll("select")
    //  console.log(selects)
     for(var j=0;j<data.length;j++){
         selects[0].add(new Option(data[j].userName,data[j].userId))
     }
var Pcontent2 = document.querySelector(".Pcontent2");
var btn1 = Pcontent2.firstElementChild;
var btn2 = Pcontent2.firstElementChild.nextElementSibling;
btn1.onclick=function(){
    mask.setAttribute("class","maskShowNone");
    addChildProject.style.display="none";
    adds.style.display="none";
    add1.style.color="#000";
    add2.style.color="#000";
    var input3=document.querySelector("#addChildProject").querySelectorAll("input")
    // console.log(input3)
    var Json2={
        childProjectName:input3[0].value,
        childProjectLeader:selects[0].value,//当前空闲人
        workingHours:input3[1].value,
        startDate:input3[2].value,
        endDate:input3[3].value,
        prop:input3[4].value,
        projectId:localStorage.getItem("projectId")
    }
    // console.log(Json2)
    ajax.post(ajax.myUrl+"project/addChildProject",Json2,function(result){ 
    console.log(result)
    })
}
btn2.onclick=function(){
    mask.setAttribute("class","maskShowNone");
    addChildProject.style.display="none";
    adds.style.display="none";
    add1.style.color="#000";
    add2.style.color="#000";
}
// // 点击子项目详情
var colors = document.querySelectorAll(".color");
for(var a=0;a<colors.length;a++){
    colors[a].onclick=function(){
        for(var b=0;b<colors.length;b++){
            if(this ==colors[b]){
                location.href="ChildProject.html"
                localStorage.setItem("childProjectId",data2[b].childProjectId)
            }
        }
    }
}

   })
   
   
   
//当鼠标经过加号时显示 下面的添加选项
var addition = document.querySelector(".addition");
// console.log(addition);
var imgs = addition.querySelector("img");
var adds = imgs.nextElementSibling;
var add1 = imgs.nextElementSibling.firstElementChild;
var add2 = imgs.nextElementSibling.firstElementChild.nextElementSibling;
var addChildProject = document.querySelector("#addChildProject");
var addChildProject2 = document.querySelector("#addChildProject2")
var mask = document.querySelector("#mask");
imgs.onmouseover = function(){
    adds.style.display="block";
}
// 选项添加点击事件
add1.onclick = function(){
    add1.style.color="#0f6ab1";
    mask.setAttribute("class","maskShow");
    addChildProject.style.display="block";
    
}
add2.onclick = function(){
    add2.style.color="#0f6ab1";
    mask.setAttribute("class","maskShow");
    addChildProject2.style.display="block";
   var Json4={

   }
   ajax.post(ajax.myUrl+"project/findFreeUser",Json4,function(result){ 
    console.log(result)
    var data3=result.dataset;
    var freeusername=[];
    var freeuserid=[]
    for(var i=0;i<data3.length;i++){
        freeusername.push(data3[i].userName)
        freeuserid.push(data3[i].userId)
    }
    localStorage.setItem("freeuserid",freeuserid)
    localStorage.setItem("freeusername",freeusername)
    var PBox = document.getElementsByClassName("PBox")[1];
    PBox.innerHTML=``
    for(var j=0;j<freeusername.length;j++){
        var Pcontent = document.createElement("div");
        Pcontent.innerHTML=`
        <div><input type="checkbox" name="" id="${freeuserid[j]}">${freeusername[j]}</div>`
        PBox.appendChild(Pcontent)
        Pcontent.setAttribute("class","Pcontent")
       
    }
    var Pcontent2=document.createElement("div");
    Pcontent2.innerHTML=`
            <button>确认</button>
            <button>取消</button>`
    PBox.appendChild(Pcontent2)
    Pcontent2.setAttribute("class","Pcontent2");
    // 给第二个模态框（添加项目）添加事件 点击取消或者确定 模态框消失
var Pcontent2 = addChildProject2.querySelector(".Pcontent2");
var btn1 = Pcontent2.firstElementChild;
var btn2 = Pcontent2.firstElementChild.nextElementSibling;
btn1.onclick=function(){
    mask.setAttribute("class","maskShowNone");
    addChildProject2.style.display="none";
    adds.style.display="none";
    add1.style.color="#000";
    add2.style.color="#000";
    var userid = localStorage.getItem("userid");
    var Json3=
        [
        
            {userId:Number(userid),
            projectId:Number(localStorage.getItem("projectId"))
            }
        ]
    
    
    ajax.post(ajax.myUrl+"project/insertProjector",Json3,function(result){ 
        console.log(result)
        })
}
btn2.onclick=function(){
    mask.setAttribute("class","maskShowNone");
    addChildProject2.style.display="none";
    adds.style.display="none";
    add1.style.color="#000";
    add2.style.color="#000";
}
    })
}



var control = document.querySelector("#control");
control.onmouseleave = function(){
    adds.style.display="none";
}
add1.onmouseover=function(){
    adds.style.display="block";
}

